<?php
/**
 * 同步Lumesse中招聘人员部门信息
 * @author dinglin
 */
apf_require_class('Oa_Job_Abstract');
apf_require_class("Bll_Flow_Lumesse");
class Oa_Job_Flow_InputLumesseDepartmentId extends Oa_Job_Abstract {
    private $write_db = "hroa_master";//写数据库
    public function run() {
        $this->log("开始同步Lumesse部门id".date('Y-m-d H:i:s'));

        $lumesse_user_organization = Bll_Flow_Lumesse::get_instance()->Lumesse_User()->Organization();
        $organizations = $lumesse_user_organization->getOrganizations();
        $organizations = $organizations->organization->organization;
        $organizations = $this->_build_data($organizations);

        $this->_update_lums_depart_id($organizations);
        $this->log("同步Lumesse部门id处理完".date('Y-m-d H:i:s'));
    }
    private function _update_lums_depart_id($organizations){
        foreach($organizations as $key=>$one){
            if($one){
                $sql = "UPDATE lumesse SET lums_depart_id =".$one." WHERE lums_depart_ename = '".$key."'";
                $this->execute($sql,array(),$this->write_db);
                $sql = "UPDATE lumesse SET lums_pdepart_id =".$one." WHERE lums_pdepart_ename = '".$key."'";
                $this->execute($sql,array(),$this->write_db);
            }
        }
    }
    private function _build_data($organizations){
        $result = array();
        foreach($organizations as $organization){
            foreach($organization->unit as $or){
                $result[$or->_] = $or->id;
            }
        }
        return $result;
    }
}